package edu.dk.dao;

import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

import java.io.Serializable;


public class CommonDAO<T, PK extends Serializable> implements GenericDAO<T, PK> {

    @Autowired
    HibernateTemplate template;

    private Class<T> type;

    public CommonDAO(Class<T> type){
         this.type = type;
    }

    @Override
    public T get(PK id) {
        return template.get(type, id);
    }

    @Override
    public void add(T entity) {
        template.save(entity);
    }

    @Override
    public void update(T entity) {
        template.saveOrUpdate(entity);
    }

    @Override
    public void delete(T entity) {
        template.delete(entity);
    }

}
